package com.lx.serv.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.lx.dao.MachineDao;
import com.lx.domain.machine;
import com.lx.serv.MachineServ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class MachineServImpl implements MachineServ {
    @Autowired
    MachineDao machineDao;

    @Override
    public List<machine> getAll() {
        return machineDao.selectList(null);
    }

    @Override
    public boolean add(machine mac) {
        return machineDao.insert(mac) > 0;
    }

    @Override
    public boolean update(machine mac) {
        LambdaUpdateWrapper<machine> lqw = new LambdaUpdateWrapper<machine>();
        lqw.eq(machine::getId, mac.getId());
        return machineDao.update(mac, lqw) > 0;
    }

    @Override
    public boolean delete(int id) {
        return machineDao.deleteById(id) > 0;
    }
}
